package com.example.lycdays.data.repositiory;

import com.example.lycdays.data.bean.Event;

import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;

public class EventDataBase {

    public static List<Event> findAllEvents() {

        List<Event> events = new ArrayList<>();

        try {
            events = LitePal.order("createTime desc").find(Event.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return events;
    }

    public static Event findEventByCreateTime(long createTime) {
        return LitePal.where("createTime = ?", String.valueOf(createTime)).findFirst(Event.class);
    }

    public static void insertEvent(Event event) {
        event.save();
    }

    public static void deleteEvent(Event event) {
        LitePal.delete(Event.class, event.getId());
    }

    public static void updateEvent(Event event) {
        event.update(event.getId());
    }


}